﻿
@{
    ViewBag.Title = "提现申请";
    Layout = "~/Views/Shared/_MallLayout.cshtml";
    var setting = ViewBag.setting as token_base_setting;
    int type = 1;
    int.TryParse(Request["type"]??"1", out type);
}
@model api_merchant_bank_card_dto
<body class="page-bank page-enchashment">

    @*<div class="lt-head">
        <a href="javascript:history.go(-1);">
            <i class="icon-back fn-left"></i>
        </a>
        <span class="center">提现申请</span>
    </div>*@
    <!--header end-->
    <form name="myform" action="">
        <div class="mod-forms ">
            <div class="ui-item">
                <div class="ui-label">提现金额  <a href="/mybill/Deposited?type=@type" class="fn-right col-blue mt10">提现记录>></a></div>
                <div class="ui-hidden">
                    <input type="text" class="ui-input" placeholder="请输入提现金额" id="amount">
                </div>
                <div class="tishi col-gray fn28">
                    实际到账金额：<em class="col-red" id="settle_amount">0.00</em>元
                    <span class="fn-right">手续费：<em class="col-red">@setting.settle_amount.ToString("f2")</em>元/笔 </span>
                </div>
            </div>
            @if (Model != null && (Model.status == EMerchantBankCardStatus.Approved || Model.status == EMerchantBankCardStatus.AutoApproved)) {
                <div class="myCard">
                    <div class="ui-card">
                        <i class="icon-bank fn-left"></i>
                        <div class="text">
                            <div>
                                <span class="fn36">
                                    <em class="fn36">@Model.bank_name</em><br>
                                    <em class="fn24">@Model.account_name.Replace(Model.account_name.Substring(1, 1), "*")</em>
                                </span>
                            </div>
                            <div class="bankNo fn36">
                                <em>****</em><em>****</em><em>****</em><em>@(Model.account_num.Length>4?Model.account_num.Substring(Model.account_num.Length - 4):Model.account_num)</em>
                            </div>
                        </div>
                    </div>
                </div>
            } else {
                if (Model == null) { <div style="text-align:center">您还未绑定银行号,请到我的银行卡管理绑定银行卡</div>}
                if (Model != null && Model.status == EMerchantBankCardStatus.AuditFail) { <div style="text-align:center;color:red">您绑定的银行卡未能审核通过,请到我的银行卡管理重新绑定银行卡</div>}
                if (Model != null && Model.status == EMerchantBankCardStatus.ToAudit) { <div style="text-align:center;color:red">您绑定的银行卡正在审核中,请等待审核结果</div>}
            }
            <div class="btnBox">
                <a href="javascript:void(0)" class="ui-btn-buy" id="transfer">提交申请</a>
            </div>
        </div>
    </form>
    <script>
        $(function(){
            //swal({
            //    title: "",
            //    text: "提交成功",
            //    timer: 3000,
            //    showConfirmButton: false
            //});
            $("#amount").bind('input porpertychange', function () {
                inputNumberChange(this, 2);
                var that = $(this);
                if (that.val().length > 0) {
                    var price = parseFloat(that.val());
                    if (price >=@setting.settle_amount) {
                         if (price >@(setting.max_withdraw)) {
                        price =@(setting.max_withdraw);
                      
                    }
                   //that.val(price.toFixed(2));
                    $("#settle_amount").text((price -@setting.settle_amount).toFixed(2));
                    }
                   
                }
                else { that.val(0); }
            });
            function myNumberic(e, len) {
                var obj = e.srcElement || e.target;
                var dot = obj.value.indexOf(".");//alert(e.which);
                len = (typeof (len) == "undefined") ? 2 : len;
                var key = e.keyCode || e.which;
                if (key == 8 || key == 9 || key == 46 || (key >= 37 && key <= 40))//这里为了兼容Firefox的backspace,tab,del,方向键
                    return true;
                if (key <= 57 && key >= 48) { //数字
                    if (dot == -1)//没有小数点
                        return true;
                    else if (obj.value.length <= dot + len)//小数位数
                        return true;
                } else if ((key == 46) && dot == -1) {//小数点
                    return true;
                }
                return false;
            }
            $("#transfer").click(function () {
                if ('@(Model== null)'=='True') { layer.msg("您还未绑定银行号,请到我的银行卡管理绑定银行卡"); return; }
                if ('@(Model != null && Model.status == EMerchantBankCardStatus.AuditFail)'=='True') {
                    layer.msg("您绑定的银行卡未能审核通过,请到我的银行卡管理重新绑定银行卡"); return;
                }
                if ('@(Model != null && Model.status == EMerchantBankCardStatus.ToAudit)'=='True') {
                    layer.msg("您绑定的银行卡正在审核中, 请等待审核结果"); return;
                }
                var price = parseFloat($("#amount").val());
                if (price <= 0) { layer.msg("请输入提现金额"); }
                if (price < @setting.min_withdraw) { layer.msg("最小提现金额最少@(setting.min_withdraw)"); return; }
                layer.load(1);
                $.post('/mybill/SaveTransfer', { type: @type, amount: price }, function (response) {
                    layer.closeAll('loading');
                    if (response.result_code == 1000) {
                        layer.msg(response.result_msg);
                        setTimeout("location.href = '/mybill/wallet'", 1000);
                        ;
                    } else {
                        layer.msg(response.result_msg);
                    }
                });
            });
        })
    </script>
    <style>
        .sa-error-container, .sa-button-container {
            display: none;
        }

        .sweet-alert h2 {
            display: none;
        }

        .sweet-alert[data-has-confirm-button=false][data-has-cancel-button=false] {
            padding-bottom: 0;
        }

        .sweet-alert p {
            line-height: 60px;
            margin: 0;
            padding: 0;
        }
    </style>
</body>

